package server

import (
	"gitee.com/wydcn/wm/protocol"
	"net"
	"fmt"
)

func Start(){
	ln, err := net.Listen("tcp", ":8888")
	if err != nil {
		// handle error
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			// handle error
		}
		go connectHandle(conn)
	}
}

func connectHandle(conn net.Conn){
	//defer conn.Close()
	for{
		var buf = make([]byte,3)
		conn.Read(buf)
		length,err := protocol.BytesToUint16(buf[1:])
		if (err != nil) {
			continue
		}
		var body = make([]byte,length)
		conn.Read(body)
		fmt.Println(string(body[:]))
	}
}
